<?php
# Interface for the RAMS client library.
#
# Copyright (C) 2008 rambla.be
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

/**
 * @file
 * Implementation of the Rams interface class.
 */

require_once dirname(__FILE__) . '/../Raws.php';
require_once dirname(__FILE__) . '/../Util.php';
require_once dirname(__FILE__) . '/Rams/TrafficEntry.php';
require_once dirname(__FILE__) . '/Rams/TrafficFeed.php';
require_once dirname(__FILE__) . '/Rams/TrafficQuery.php';
require_once dirname(__FILE__) . '/Rams/StorageEntry.php';
require_once dirname(__FILE__) . '/Rams/StorageFeed.php';
require_once dirname(__FILE__) . '/Rams/StorageQuery.php';
require_once dirname(__FILE__) . '/Rams/FilterEntry.php';
require_once dirname(__FILE__) . '/Rams/FilterFeed.php';
require_once dirname(__FILE__) . '/Rams/FilterQuery.php';

/**
 * Class containing interface methods for RAMS API.
 **/
class Rams extends Raws
{
    public static $namespaces = array(
            'raws' => 'http://rambla.be/raws/ns-metadata/1.0');

    public function __construct($user = null, $pwd = null, $base_uri = null, $path = null, $client = null, $applicationId = 'MyCompany-MyApp-1.0')
    {
      if (! $base_uri) {
        $base_uri = "http://rams.cdn01.rambla.be";
      }
      $this->registerPackage('Rams');
      $this->registerPackage('Rams_Extension');
      parent::__construct($user, $pwd, $base_uri, $path, $client, $applicationId);
    }

    /**
     * Retrieve the feed for a RAMS Traffic instance.
     *
     * @param string $path The relative path to the directory.
     * @param TrafficQuery $query An object of type TrafficQuery, or null for no query-string.
     * @return Rams DirFeed object
     */
    public function getTrafficFeed($path = null, $query = null)
    {
      $resource = "traffic";
      if ($query) {
        # let the query-obj compose the uri, when present
        $uri = $query->getQueryUrl($this->getBaseUri(), $path);
      }
      else {
        # no query obj, compose URI without query-string
        $uri = safe_raws_uri($this->getBaseUri(), $resource, $path);
      }
      return parent::getFeed($uri, 'Rams_TrafficFeed');
    }

    /**
     * Retrieve the feed for a RAMS Storage instance.
     *
     * @param string $path The relative path to the directory.
     * @param StorageQuery $query An object of type StorageQuery, or null for no query-string.
     * @return Rams DirFeed object
     */
    public function getStorageFeed($path = null, $query = null)
    {
      $resource = "storage";
      if ($query) {
        # let the query-obj compose the uri, when present
        $uri = $query->getQueryUrl($this->getBaseUri(), $path);
      }
      else {
        # no query obj, compose URI without query-string
        $uri = safe_raws_uri($this->getBaseUri(), $resource, $path);
      }
      return parent::getFeed($uri, 'Rams_StorageFeed');
    }
    
    /**
     * Retrieve the feed for a RAMS Filter instance.
     *
     * @param string $path The relative path to the directory.
     * @param FilterQuery $query An object of type FilterQuery, or null for no query-string.
     * @return Rams DirFeed object
     */
    public function getFilterFeed($path = null, $query = null)
    {
      $resource = "filter";
      if ($query) {
        # let the query-obj compose the uri, when present
        $uri = $query->getQueryUrl($this->getBaseUri(), $path);
      }
      else {
        # no query obj, compose URI without query-string
        $uri = safe_raws_uri($this->getBaseUri(), $resource, $path);
      }
      return parent::getFeed($uri, 'Rams_FilterFeed');
    }

}
